package com.minglead.crawler.util;

import cn.hutool.core.util.ObjectUtil;
import com.minglead.crawler.entity.SelectEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * @author bxh
 * @Description 舆情文章分类
 * @date 2024/8/1
 */
public enum TextTypeEnum {
    //文章分类，0:财经 1:教育 2:房产 3:星座 4:科技 5:时尚 6:彩票 7:体育 8:游戏 9:时政 10:股票 11:娱乐 12:社会 13:家居
    CJ("0", "财经"),
    JY("1", "教育"),
    FC("2", "房产"),
    XZ("3", "星座"),
    KJ("4", "科技"),
    SS("5", "时尚"),
    CP("6", "彩票"),
    TY("7", "体育"),
    YX("8", "游戏"),
    SZ("9", "时政"),
    GP("10", "股票"),
    YL("11", "娱乐"),
    SH("12", "社会"),
    JJ("13", "家居");


    /** 枚举值 */
    private final String code;

    /** 枚举描述 */
    private final String description;


    TextTypeEnum(String code, String message) {
        this.code = code;
        this.description = message;
    }

    public String getCode() {
        return code;
    }

    public String getMessage() {
        return description;
    }

    /**
     * 获取下拉列表填充数据
     * @return 下拉列表填充数据
     */
    public static List<SelectEntity> getSelectList() {
        List<SelectEntity> result = new ArrayList<>();
        for (TextTypeEnum row :
                TextTypeEnum.values()) {
            SelectEntity data = new SelectEntity();
            data.setLabel(row.description);
            data.setVal(row.code);
            result.add(data);
        }
        return result;
    }

    public static TextTypeEnum getEnum(String code) {
        if (ObjectUtil.isNotNull(code)) {
            TextTypeEnum[] VALUES = TextTypeEnum.values();
            for (TextTypeEnum ele : VALUES) {
                if (StringUtils.equals(ele.code,code)) {
                    return ele;
                }
            }
        }
        return null;
    }
}
